home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / blix / bliximage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.2 KB  |  151 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*__________________________________________________________________________
  18.  |
  19.  | bliximage.c - the main part of the blix program
  20.  |
  21.  |
  22.  |     (c) 1993 Frans van Hoesel, Xtreme graphics software
  23.  |    hoesel@chem.rug.nl
  24. */
  25.  
  26.  
  27.  
  28. #include <alloca.h>
  29. #include <math.h>
  30. #include <gl/gl.h>
  31. #include <gl/device.h>
  32. #include <gl/get.h>
  33. #include <gl/sphere.h>
  34. #include <gl/image.h>
  35.  
  36. #include "bliximage.h"
  37. #include "blixui.h"
  38.  
  39. /* from imagelib: */
  40. IMAGE *iopen();
  41. void getrow(IMAGE *, short *, int , int);
  42. void iclose(IMAGE *);
  43.  
  44. /*________________________________________________________________________
  45.  |
  46.  | draw_image - draw a 2d image image
  47.  |
  48.  | draw a 2d image at the given coordinates; the coordianates are floats
  49.  | in the range 0.0-1.0 and are the corners of image. The aspect ratio of
  50.  | the image is preserved regardless of the coordinates you give.
  51.  |
  52. */
  53.  
  54. void draw_image(IMAGE *image, float xmin, float xmax, float ymin, float ymax) {
  55.     
  56.     short *rbuf, *gbuf, *bbuf, *rbuf2, *gbuf2, *bbuf2, *tmpp;
  57.     float v1[2], v2[2];
  58.     int x, y;
  59.     int stp;
  60.     float stpf;
  61.     float max_size;
  62.     float fac;
  63.     float xoffset, yoffset;
  64.     
  65.     if (image == NULL) {
  66.     return;
  67.     }
  68.     max_size = image->xsize;
  69.     fac = max_size / (xmax - xmin);
  70.     if (image->ysize > max_size) {
  71.     max_size = image->ysize;
  72.     fac = max_size / (ymax - ymin);
  73.     }
  74.     xoffset = ((xmax - xmin) * fac - image->xsize) / 2;
  75.     yoffset = ((ymax - ymin) * fac - image->ysize) / 2;
  76.     ortho2(-xmin * fac - xoffset, (1-xmin) * fac - xoffset,
  77.         -ymin * fac - yoffset,(1-ymin) * fac - yoffset);
  78.     rbuf = (short*) alloca(image->xsize*sizeof(short));
  79.     gbuf = (short*) alloca(image->xsize*sizeof(short));
  80.     bbuf = (short*) alloca(image->xsize*sizeof(short));
  81.     rbuf2 = (short*) alloca(image->xsize*sizeof(short));
  82.     gbuf2 = (short*) alloca(image->xsize*sizeof(short));
  83.     bbuf2 = (short*) alloca(image->xsize*sizeof(short));
  84.     getrow(image, rbuf2, image->ysize-1, 0);
  85.     getrow(image, gbuf2, image->ysize-1, 1);
  86.     getrow(image, bbuf2, image->ysize-1, 2);
  87.     stpf = fac / (float) sizey;
  88.     lmbind(MATERIAL,0);
  89.     if (stpf > 1.0) {
  90.     /* draw the image using points */
  91.     stp = stpf;
  92.     for (y=image->ysize - 1 - stp; y >= 0; y -= stp) {
  93.         tmpp = rbuf2; rbuf2 = rbuf; rbuf = tmpp;
  94.         tmpp = gbuf2; gbuf2 = gbuf; gbuf = tmpp;
  95.         tmpp = bbuf2; bbuf2 = bbuf; bbuf = tmpp;
  96.         getrow(image, rbuf2, y, 0);
  97.         getrow(image, gbuf2, y, 1);
  98.         getrow(image, bbuf2, y, 2);
  99.         v1[0] = 0;
  100.         v1[1] = y;
  101.         bgnpoint();
  102.         for (x=0; x < image->xsize; x+=stp) {
  103.         RGBcolor(*(rbuf2+x) , *(gbuf2+x), *(bbuf2+x));
  104.         v2f(v1);
  105.         v1[0] += stp;
  106.         }
  107.         endpoint();
  108.     }
  109.     } else {
  110.     /* draw the image using tmesh */
  111.     backface(FALSE);
  112.     for (y=image->ysize-2; y >= 0; y --) {
  113.         tmpp = rbuf2; rbuf2 = rbuf; rbuf = tmpp;
  114.         tmpp = gbuf2; gbuf2 = gbuf; gbuf = tmpp;
  115.         tmpp = bbuf2; bbuf2 = bbuf; bbuf = tmpp;
  116.         getrow(image, rbuf2, y, 0);
  117.         getrow(image, gbuf2, y, 1);
  118.         getrow(image, bbuf2, y, 2);
  119.         v1[0] = 0;
  120.         v1[1] = y;
  121.         v2[0] = 0;
  122.         v2[1] = y+1;
  123.         bgntmesh();
  124.         for (x=0; x < image->xsize; x++) {
  125.         RGBcolor(*(rbuf2+x), *(gbuf2+x), *(bbuf2+x));
  126.         v2f(v1);
  127.         v1[0] += 1;
  128.         RGBcolor(*(rbuf+x), *(gbuf+x), *(bbuf+x));
  129.         v2f(v2);
  130.         v2[0] += 1;
  131.         }
  132.         endtmesh();
  133.     }
  134.     backface(TRUE);
  135.     }
  136.     RGBcolor(0,0,0);
  137.     linewidth(1);
  138.     bgnclosedline();
  139.     v1[0] = 0;
  140.     v1[1] = 0;
  141.     v2f(v1);
  142.     v1[1] = image->ysize-1;
  143.     v2f(v1);
  144.     v1[0] = image->xsize-1;
  145.     v2f(v1);
  146.     v1[1] = 0;
  147.     v2f(v1);
  148.     endclosedline();
  149. }
  150.  
  151.